//
//  YYSCenterController.m
//  FanLaiWu
//
//  Created by gonglei on 17/3/14.
//  Copyright © 2017年 yys. All rights reserved.
//

#import "YYSCenterController.h"
#import "YYSLoginController.h"
#import "YYSSheZhiController.h"
#import "YYSUserController.h"
#import "YYSOpenVipController.h"
#import "YYSReadSaveController.h"
#import "YYSLiXianSaveController.h"
#import <Photos/Photos.h>
@interface YYSCenterController ()<UIImagePickerControllerDelegate,UINavigationControllerDelegate>
@property (weak, nonatomic) IBOutlet UIView *loginView;
@property (weak, nonatomic) IBOutlet UIView *readRecond;
@property (weak, nonatomic) IBOutlet UIView *liXianSave;
@property (weak, nonatomic) IBOutlet UIView *shareView;
@property (weak, nonatomic) IBOutlet UIView *shangChuanView;
@property (weak, nonatomic) IBOutlet UIView *kaiTongVipView;

@property (weak, nonatomic) IBOutlet UIImageView *iconImageV;
@property (weak, nonatomic) IBOutlet UILabel *userLabel;
@property (nonatomic, strong) UIImagePickerController *pickerVC;
@end

@implementation YYSCenterController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view from its nib.
    UILabel *label = [[UILabel alloc] initWithFrame:CGRectMake(0, 0, 100, 44)];
    label.text = @"个人中心";
    label.textAlignment = NSTextAlignmentCenter;
    label.textColor = [UIColor whiteColor];
    self.navigationItem.titleView = label;
    
    UIButton *btn = [[UIButton alloc] initWithFrame:CGRectMake(0, 0, 25, 25)];
    [btn setImage:[UIImage imageNamed:@"shezhi"] forState:UIControlStateNormal];
    [btn addTarget:self action:@selector(clickSheZhi:) forControlEvents:UIControlEventTouchUpInside];
    self.navigationItem.rightBarButtonItem = [[UIBarButtonItem alloc] initWithCustomView:btn];
    
    
    [self.loginView addGestureRecognizer:[[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(clickLogin:)]];
    self.loginView.userInteractionEnabled = YES;
    
    [self.kaiTongVipView addGestureRecognizer:[[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(clicVip:)]];
    self.kaiTongVipView.userInteractionEnabled = YES;
    
    [self.readRecond addGestureRecognizer:[[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(clicSave:)]];
    self.readRecond.userInteractionEnabled = YES;
    
    [self.liXianSave addGestureRecognizer:[[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(clicliXian:)]];
    self.liXianSave.userInteractionEnabled = YES;
    
    [self.shareView addGestureRecognizer:[[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(share:)]];
    self.shareView.userInteractionEnabled = YES;
    
    [self.shangChuanView addGestureRecognizer:[[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(shangChuan:)]];
    self.shangChuanView.userInteractionEnabled = YES;
    
    self.iconImageV.layer.masksToBounds = YES;
    self.iconImageV.layer.cornerRadius = 5;
    
    
    
}
-(void)viewDidAppear:(BOOL)animated
{
    [super viewDidAppear:animated];
    self.navigationController.navigationBar.hidden = NO;
    if (TOKEN) {
        self.userLabel.text = [[SaveManager shareSaveManager] getUserName];
    } else
    {
        self.userLabel.text = @"点击登录／注册";
    }
    if (self.iconImage) {
        self.iconImageV.image = self.iconImage;
        
    }
}
- (void)shangChuan:(UITapGestureRecognizer *)tap
{
    
    //NSLog(@"相册");
    self.pickerVC.sourceType = UIImagePickerControllerSourceTypeSavedPhotosAlbum;
    //相机类型（拍照、录像...）字符串需要做相应的类型转换
    
    self.pickerVC.mediaTypes = @[(NSString *)kUTTypeMovie];
    [self presentViewController:self.pickerVC animated:YES completion:nil];
    
}
- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary<NSString *,id> *)info
{
    NSLog(@"%@",info);
     [picker dismissViewControllerAnimated:NO completion:nil];
}
- (UIImagePickerController *)pickerVC {
    if (!_pickerVC) {
        _pickerVC = [[UIImagePickerController alloc] init];
        _pickerVC.delegate = self;
        _pickerVC.modalTransitionStyle = UIModalTransitionStyleCoverVertical;
    }
    return _pickerVC;
}
- (void)clickSheZhi:(UIButton *)btn
{
    YYSSheZhiController *shezhi = [[YYSSheZhiController alloc] init];
    [self.navigationController pushViewController:shezhi animated:YES];
}
- (void)clicVip:(UITapGestureRecognizer *)tap
{
    YYSOpenVipController *open = [[YYSOpenVipController alloc] init];
    [self.navigationController pushViewController:open animated:YES];
}
- (void)clicSave:(UIButton *)btn
{
    YYSReadSaveController *read = [[YYSReadSaveController alloc] init];
    read.title = @"浏览记录";
    [self.navigationController pushViewController:read animated:YES];
}

- (void)clicliXian:(UIButton *)btn
{
    YYSReadSaveController *read = [[YYSReadSaveController alloc] init];
    read.title = @"离线缓存";
    [self.navigationController pushViewController:read animated:YES];
}
- (void)share:(UIButton *)btn
{
    [UMSocialUIManager setPreDefinePlatforms:@[@(UMSocialPlatformType_WechatSession),@(UMSocialPlatformType_WechatTimeLine),@(UMSocialPlatformType_QQ),@(UMSocialPlatformType_Qzone)]];
    [UMSocialUIManager showShareMenuViewInWindowWithPlatformSelectionBlock:^(UMSocialPlatformType platformType, NSDictionary *userInfo) {
        // 根据获取的platformType确定所选平台进行下一步操作
        //创建分享消息对象
        UMSocialMessageObject *messageObject = [UMSocialMessageObject messageObject];
        
        //创建网页内容对象
        NSString* thumbURL =  @"https://mobile.umeng.com/images/pic/home/social/img-1.png";
        UMShareWebpageObject *shareObject = [UMShareWebpageObject shareObjectWithTitle:@"欢迎使用【友盟+】社会化组件U-Share" descr:@"欢迎使用【友盟+】社会化组件U-Share，SDK包最小，集成成本最低，助力您的产品开发、运营与推广！" thumImage:thumbURL];
        //设置网页地址
        shareObject.webpageUrl = @"http://mobile.umeng.com/social";
        
        //分享消息对象设置分享内容对象
        messageObject.shareObject = shareObject;
        
        //调用分享接口
        [[UMSocialManager defaultManager] shareToPlatform:platformType messageObject:messageObject currentViewController:self completion:^(id data, NSError *error) {
            if (error) {
                UMSocialLogInfo(@"************Share fail with error %@*********",error);
            }else{
                if ([data isKindOfClass:[UMSocialShareResponse class]]) {
                    UMSocialShareResponse *resp = data;
                    //分享结果消息
                    UMSocialLogInfo(@"response message is %@",resp.message);
                    //第三方原始返回的数据
                    UMSocialLogInfo(@"response originalResponse data is %@",resp.originalResponse);
                    
                }else{
                    UMSocialLogInfo(@"response data is %@",data);
                }
            }
            
        }];
    }];
}
- (void)clickLogin:(UITapGestureRecognizer *)tap
{
    if (TOKEN) {
        YYSUserController *user = [[YYSUserController alloc] init];
        user.center = self;
        [self.navigationController pushViewController:user animated:YES];
    } else {
        
        YYSLoginController *login = [[YYSLoginController alloc] init];
        [self presentViewController:login animated:YES completion:^{
            
        }];
    }
}
- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
